/*+**************************************************************************/
/***                                                                      ***/
/***   This file is distributed under a BSD license.                      ***/
/***   See LICENSE.txt for details.                                       ***/
/***                                                                      ***/
/**************************************************************************+*/

/****************************************************************************/
/***                                                                      ***/
/***   (C) 2005 Dierk Ohlerich, all rights reserved                       ***/
/***                                                                      ***/
/****************************************************************************/

asc 
{
  cbuffer TorusPara: register(c0) : slot vs 0
  {
    row_major float4x4 mvp; 
    float scale;
  };
}

material TorusShader
{

  // the vertex sahder

  vs
  {
    asc vs_3_0                 // hlsl code
    {
      use TorusPara;
      sampler2D s0 : register(s0);

      void main
      (
        in float3 in_pos : POSITION,            // input, from vertex array
        in float3 in_norm : NORMAL,            // input, from vertex array
        in float2 in_uv : TEXCOORD0,

        out float2 out_uv : TEXCOORD0,
        out float4 out_color : COLOR0,
        out float4 out_pos : POSITION,          // output, to pixel shader

//        uniform row_major float4x4 mvp : register(c0),   // shader constants
//        uniform float4 scale : register(c4)              // please use 
      )
      {
        out_uv = in_uv;
        float4 displace = tex2Dlod(s0,float4(in_uv.xy,0,0)).x*scale;
        out_color = float4(1,1,1,1);
        float4 temp = float4(in_pos+in_norm*displace.x,1);
        out_pos = mul(temp,mvp);
      }
    }
  }

  // the pixel shader. same as vertex shader...

  ps
  {
    asc ps_3_0
    {
      sampler2D s0 : register(s0);

      void main
      (
        in float2 uv : TEXCOORD0,
        in float4 col : COLOR0,
        out float4 result : COLOR0
      )
      {
        result = tex2D(s0,uv)*col;
      }
    }
  }
};
